package cn.juque.jdfsystem.disruptor.event;

import cn.juque.common.base.DisruptorBody;
import cn.juque.common.disruptor.IBusinessEventService;
import cn.juque.jdfsystem.disruptor.bo.FileDeleteBodyBO;
import cn.juque.jdfsystem.task.ClearInValidFileTask;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>FileDeleteDisruptorEventServiceImpl</li>
 * </ul>
 * @date 2023-01-18 11:11:41
 **/
@Service("fileDeleteDisruptorEventService")
public class FileDeleteDisruptorEventServiceImpl implements IBusinessEventService {

    public static final String BEAN = "fileDeleteDisruptorEventService";

    @Resource
    private ClearInValidFileTask clearInValidFileTask;

    /**
     * 具体消费者的实现
     *
     * @param disruptorBody 消息体
     */
    @Override
    public void invoke(DisruptorBody disruptorBody) {
        if (disruptorBody instanceof FileDeleteBodyBO) {
            FileDeleteBodyBO fileDeleteBodyBO = (FileDeleteBodyBO) disruptorBody;
            List<String> pathList = fileDeleteBodyBO.getAbsolutePathList();
            String[] array = new String[pathList.size()];
            for (int i = 0; i < pathList.size(); i++) {
                array[i] = pathList.get(i);
            }
            this.clearInValidFileTask.start(array);
        }
    }
}
